package com.cax.module.tran.controller;

import com.cax.common.core.domain.Result;
import com.cax.common.core.validate.Group;
import com.cax.module.file.domain.FileType;
import com.cax.module.file.domain.vo.File2VO;
import com.cax.module.file.service.FileService;
import com.cax.module.tran.domain.dto.TrainCertificateAddOrUpdDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import com.cax.module.tran.service.TrainCertificateService;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.cax.module.tran.domain.TrainCertificate;
import com.cax.module.tran.domain.vo.TrainCertificateVO;
import com.cax.module.tran.domain.dto.TrainCertificatePageQueryDTO;
import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 培训证书管理表 Controller控制层
 * @author makejava
 * @date 2024-09-24 11:31:31
 */
@Slf4j
@RestController
@Api(tags = "培训证书管理表-TrainCertificate-Api")
@RequestMapping("/trainCertificate")
@Validated
public class TrainCertificateController {
    /**
     * 培训证书管理表 Service
     */
    @Autowired
    public TrainCertificateService trainCertificateService;
	@Autowired
    public FileService fileService;

    @GetMapping("/getPage")
    @ApiOperation(value = "分页查询", notes = "")
	public Result<Page<TrainCertificate>> getByPage(
		@Validated TrainCertificatePageQueryDTO dto
	) {
		Page<TrainCertificate> result = trainCertificateService.getPage(dto);
		return Result.ok(result);
	}

    @GetMapping("/getByKey")
    @ApiOperation(value = "通过主键查询", notes = "")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "int"),
	})
	public Result<TrainCertificateVO> getByKey(
			@NotNull(message = "参数id不能为空")Integer id
	) {
		TrainCertificateVO result = trainCertificateService.getByKey(id);
		return Result.ok(result);
	}

	@GetMapping("/query/noAuth")
	@ApiOperation(value = "通过姓名、身份证精确查询", notes = "")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "name", value = "姓名", required = true, dataType = "String"),
			@ApiImplicitParam(name = "identityCard", value = "身份证", required = true, dataType = "String"),
	})
	public Result<List<TrainCertificateVO>> getByNameIdentityCard(
			@RequestParam(name = "name")String name,
			@RequestParam(name = "identityCard")String identityCard
	) {
		List<TrainCertificateVO> result = trainCertificateService.getByNameIdentityCard(name,identityCard);
		return Result.ok(result);
	}

	@PostMapping("file")
	@ApiOperation(value = "上传-证书图片", notes = "")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "file", value = "证书图片", required = true, dataType = "MultipartFile"),
	})
	public Result<File2VO> addRichFile(
			@RequestParam(name = "file") MultipartFile file
	) {
		File2VO result = fileService.upload(FileType.TypeEnum.FILE_TYPE_4.getCode(),file);
		return Result.ok(result);
	}

	@PostMapping("/add")
    @ApiOperation(value = "添加", notes = "")
	public Result<Integer> add(
		@RequestBody @Validated(Group.Add.class) TrainCertificateAddOrUpdDTO dto
	) {
		Integer result = trainCertificateService.add(dto);
		return Result.ok(result);
	}

	@PostMapping("/upd")
    @ApiOperation(value = "通过主键修改", notes = "")
	public Result upd(
		@RequestBody @Validated(Group.Upd.class) TrainCertificateAddOrUpdDTO dto
	) {
		trainCertificateService.upd(dto);
		return Result.ok();
	}

	@PostMapping("/del/{id}")
	@ApiOperation(value = "通过主键删除", notes = "")
	public Result del(
			@PathVariable Integer id
	) {
		trainCertificateService.del(id);
		return Result.ok();
	}
}

